package com.chen.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

public class Test2 {
    public static final Lock lock = new ReentrantLock();
    static Condition condition1 = lock.newCondition();
    static Condition condition2 = lock.newCondition();
    static Condition condition3 = lock.newCondition();

    public static void main(String[] args) {
//        String substring1 = "23030101AB0005090101".substring(12, 14);
//        String substring2 = "23030101AB0005090101".substring(14, 16);
//        System.out.println(substring1);
//        System.out.println(substring2);

        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        List<String> collect = list.stream().map(x -> {
            return x.concat("--->test");
        }).collect(Collectors.toList());
        System.out.println(collect.toString());
    }

    public static void print() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
//        System.out.println(Thread.currentThread().getName() + "打印了：" + i);
    }


    static class print implements Runnable {
        private int treadId;

        public print(int treadId) {
            this.treadId = treadId;
        }

        @Override
        public void run() {
            lock.lock();
            try {
                condition1.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            try {
                condition2.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            try {
                condition3.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            for (int i = 0; i < 100; i++) {
                if (i % 3 == 0) {
                    condition1.signal();
                }

            }
        }
    }
}

